/*
 * @Descripttion: 
 * @version: 
 * @Author: turingchang
 * @Date: 2020-12-22 15:34:10
 * @LastEditors: turingchang
 * @LastEditTime: 2020-12-25 16:56:30
 */

'use strict';
const BaseController = require('../base/base');

class JobController extends BaseController {
    
    /**
     * 添加计划任务.post
     */
    async add(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.request.body);
        let res = await ctx.service.job.job.add(params);        
        if(res.success === false){
            return ctx.outError(res.msg || '添加失败',null,res.response_code_enum || ctx.app.enums.response_code_enum.server_error);
        }
        ctx.outSuccess('添加成功');
    }

    /**
     * 取消计划任务
     */
    async cancel(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.request.body);
        let res = await ctx.service.job.job.cancel(params);
        if(res.success === false){
            return ctx.outError(res.msg || '取消失败',null,res.response_code_enum || ctx.app.enums.response_code_enum.server_error);
        }
        ctx.outSuccess('取消成功');
    }

    /**
     * 
     */
    async get(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.query);
        let res = await ctx.service.job.job.getSystemSchedule(params);        
        ctx.outSuccess('');
    }

    async edit(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.request.body);
        let res = await ctx.service.job.job.edit(params);        
        if(res.success === false){
            return ctx.outError(res.msg || '编辑失败',null,res.response_code_enum || ctx.app.enums.response_code_enum.server_error);
        }
        ctx.outSuccess('编辑成功');
    }

    async start(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.request.body);
        let res = await ctx.service.job.job.start(params);        
        if(res.success === false){
            return ctx.outError(res.msg || '启动失败',null,res.response_code_enum || ctx.app.enums.response_code_enum.server_error);
        }
        ctx.outSuccess('启动成功');
    }
    async stop(){
        const ctx =this.ctx;
        let params = {};
        params = Object.assign(params,ctx.request.body);
        let res = await ctx.service.job.job.stop(params);        
        if(res.success === false){
            return ctx.outError(res.msg || '停止失败',null,res.response_code_enum || ctx.app.enums.response_code_enum.server_error);
        }
        ctx.outSuccess('停止成功');
    }

    
}

module.exports = JobController;